package com.jdk21.api.common;

import com.jdk21.api.enums.ErrorCodeEnum;
import lombok.Data;

@Data
public class Response<T> {

    private T data;

    private boolean success;

    private String code;

    private String msg;

    public static <T> Response<T> successResult(T data) {
        Response<T> response = new Response<>();
        response.setSuccess(true);
        response.setCode(ErrorCodeEnum.SUCCESS.getCode());
        response.setData(data);
        return response;
    }

    public static <T> Response<T> successResult(T data, String msg) {
        Response<T> response = new Response<>();
        response.setSuccess(true);
        response.setCode(ErrorCodeEnum.SUCCESS.getCode());
        response.setData(data);
        response.setMsg(msg);
        return response;
    }

    public static <T> Response<T> failResult(String code, String msg) {
        Response<T> response = new Response<>();
        response.setSuccess(false);
        response.setCode(code);
        response.setMsg(msg);
        return response;
    }

    public static <T> Response<T> failResult(ErrorCodeEnum errorCodeEnum, String msg) {
        Response<T> response = new Response<>();
        response.setSuccess(false);
        response.setCode(errorCodeEnum.getCode());
        response.setMsg(msg);
        return response;
    }

    public static <T> Response<T> failResult(ErrorCodeEnum errorCodeEnum) {
        Response<T> response = new Response<>();
        response.setSuccess(false);
        response.setCode(errorCodeEnum.getCode());
        response.setMsg(errorCodeEnum.getDesc());
        return response;
    }
}
